﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WenFrame
{
    public partial class StartForm : WenSkin.Forms.WenTabControlForm
    {
        private const int CS_DropSHADOW = 0x20000;
        private const int GCL_STYLE = (-26);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetClassLong(IntPtr hwnd, int nIndex);

        private void SetShadow()
        {
            SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
        }

        private readonly WenSkin.WenConfig config = new WenSkin.WenConfig();


        #region  公有属性

        [Category("Wen"), Description("软件名称"), DefaultValue("")]
        public string SSoftwareName { get; set; } = "文林软件开发框架";

        [Category("Wen"), Description("软件说明信息"), DefaultValue("")]
        public string SoftwareInfo { get; set; } = "开发：文林 版本：V10.0.0.1 ©2020";

        #endregion

        public static StartForm startForm;
        public StartForm()
        {
            SetShadow();
            InitializeComponent();
            startForm = this;
            UserInfo.UserName = config["UserConfig", "UserName"];
            BottomText = $"登录用户:{config["UserConfig", "UserName"]}  登录时间:{DateTime.Now:yyyy/MM/dd}" +
                $"              {SoftwareInfo}   软件：{SSoftwareName}   \t";
            Text = "数据处理";
            new WenUserControlPower(this.Name).SetPower(this.LeftMenu);

        }

        private void StartForm_TabControlAdd(object sender, TabControlAddEventArgs e)
        {
            if (e.Control != null)
                return;

            switch (e.Text)
            {

                case "账户管理":
                    e.State = false;
                    new Login.SetPassword(this).ShowDialog();
                    break;
                case "用户管理":
                    e.Control = new UserControls.UserAdmin.UserAdminUserControl();
                    break;
                case "测试":
                    e.Control = new UserControls.WenUserControlTem();
                    break;
                default:
                    break;
            }
        }
        private void StartForm_ConfigButtonClick(object sender, EventArgs e)
        {
            var fm = new WenSkin.WenConfig();
            fm.ShowDialog();
        }
    }
}
